package com.example.pet.service.impl;

import com.example.pet.beans.UserInfo;
import com.example.pet.common.Result;
import com.example.pet.mapper.IUserInfoMapper;
import com.example.pet.service.IUserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liukai
 * @version 1.0.0
 * @ClassName UserInfoServiceImpl.java
 * @Description TODO
 * @createTime 2021年04月20日 16:34:00
 */
@Service
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private IUserInfoMapper iUserInfoMapper;

    @Override
    public Result login(UserInfo userInfo) {
        UserInfo info = iUserInfoMapper.findUserInfoByUserInfo(userInfo.getUserId(), userInfo.getUserPass());
        System.out.println(info);
        if (info != null){
            return Result.succ(200,"登录成功",info);
        }
        return Result.fail("登录失败");
    }

    @Override
    public Result register(UserInfo userInfo) {
        int i = iUserInfoMapper.addUserInfo(userInfo);
        if (i > 0){
            return Result.succ(200,"注册成功",userInfo);
        }
        return Result.fail("注册失败");
    }

    /**
     * 根据用户id查找用户名
     * @param userId
     * @return
     */
    @Override
    public Result findUserNameById(Integer userId) {
        String userName = iUserInfoMapper.findUserNameById(userId);
        return Result.succ(userName);
    }


}
